#include "include/high_precision_timer.hpp"
#include <iostream>

using namespace qOS;

int main() {
    std::cout << "HighPrecisionTimer Example" << std::endl;
    std::cout << "========================" << std::endl;
    
    // Test basic timer functionality
    HighPrecisionTimer timer1;
    
    // Set a 500ms timer
    timer1.set(500_ms);
    std::cout << "Timer set for 500ms" << std::endl;
    
    // Test status
    std::cout << "Timer status: " << (timer1.status() ? "ARMED" : "DISARMED") << std::endl;
    
    // Test elapsed time
    std::cout << "Elapsed time: " << timer1.elapsed() << " microseconds" << std::endl;
    
    // Test remaining time
    std::cout << "Remaining time: " << timer1.remaining() << " microseconds" << std::endl;
    
    // Test microsecond delay
    std::cout << "Testing 100us delay..." << std::endl;
    uint64_t start = HighPrecisionTimer::getMicroseconds();
    HighPrecisionTimer::delayMicroseconds(100);
    uint64_t end = HighPrecisionTimer::getMicroseconds();
    std::cout << "Actual delay: " << (end - start) << " microseconds" << std::endl;
    
    // Test compatibility with duration literals
    std::cout << "Testing 0.5 second delay..." << std::endl;
    start = HighPrecisionTimer::getMicroseconds();
    HighPrecisionTimer::delay(0.5_sec);
    end = HighPrecisionTimer::getMicroseconds();
    std::cout << "Actual delay: " << (end - start) << " microseconds" << std::endl;
    
    // Test operator compatibility
    HighPrecisionTimer timer2(200_ms);
    std::cout << "Timer2 interval: " << timer2.getInterval() << " microseconds" << std::endl;
    
    // Test assignment operators
    timer2 = 100_ms;  // Set new interval
    timer2 = true;     // Reload
    timer2 = false;    // Disarm
    
    // Test function call operators
    timer2(50_ms);     // Set interval
    bool expired = timer2();  // Check expiration
    timer2(true);      // Reload
    
    // Test boolean conversion
    if (timer2) {
        std::cout << "Timer2 has expired" << std::endl;
    } else {
        std::cout << "Timer2 has not expired" << std::endl;
    }
    
    // Test comparison operator
    if (timer2 == true) {
        std::cout << "Timer2 comparison: expired" << std::endl;
    }
    
    std::cout << "Example completed successfully!" << std::endl;
    
    return 0;
}